#!/usr/bin/python3

import smbus
import time

DEVICE_ADDR = 0x3C
DEVICE_CMD  = 0x80
DEVICE_DATA = 0xC0

bus = smbus.SMBus(1)


def transfer_command_lcd(cmd):
	bus.write_i2c_block_data(DEVICE_ADDR, DEVICE_CMD, [cmd])

def transfer_data_lcd(data):
	bus.write_i2c_block_data(DEVICE_ADDR, DEVICE_DATA, [data])

def lcd_address(x,y,x_total,y_total):
	# x=x
	# y=y

	transfer_command_lcd(0x15)
	transfer_data_lcd(x)
	transfer_data_lcd(x+x_total-1)

	transfer_command_lcd(0x75)
	transfer_data_lcd(y)
	transfer_data_lcd(y+y_total-1)
	transfer_command_lcd(0x30)
	transfer_command_lcd(0x5c)

def clear_screen():
	lcd_address(0,0,256,16)
	for i in range(0, 16):
		for j in range(0, 256):
			transfer_data_lcd(0x00)

def test(line):
        lcd_address(0, 0, 256, 16)
        for i in range(16):
            for j in range(256):
                if i < 14:
                    transfer_data_lcd(0xaa)
                else:
                    transfer_data_lcd(0x55)

transfer_command_lcd(0x30)  
transfer_command_lcd(0x94)
transfer_command_lcd(0x31)
transfer_command_lcd(0xD7)  
transfer_data_lcd(0X9F) 

transfer_command_lcd(0x32) 
transfer_data_lcd(0x00)  
transfer_data_lcd(0x01)  
transfer_data_lcd(0x04) 

transfer_command_lcd(0x20) 
transfer_data_lcd(0x01)   
transfer_data_lcd(0x03)
transfer_data_lcd(0x05)  
transfer_data_lcd(0x07)   
transfer_data_lcd(0x09)  
transfer_data_lcd(0x0b)  
transfer_data_lcd(0x0d)  
transfer_data_lcd(0x10)  
transfer_data_lcd(0x11)  
transfer_data_lcd(0x13)  
transfer_data_lcd(0x15)  
transfer_data_lcd(0x17)  

transfer_data_lcd(0x19)  
transfer_data_lcd(0x1b)  
transfer_data_lcd(0x1d)  
transfer_data_lcd(0x1f) 

transfer_command_lcd(0x30)  
transfer_command_lcd(0x75) 
transfer_data_lcd(0X00)  
transfer_data_lcd(0X1f)  
transfer_command_lcd(0x15)  
transfer_data_lcd(0X00)  
transfer_data_lcd(0Xff) 

transfer_command_lcd(0xBC) 
transfer_data_lcd(0x00)  

transfer_command_lcd(0xA6)   
transfer_command_lcd(0x0c) 

transfer_command_lcd(0xCA) 
transfer_data_lcd(0X00)   
transfer_data_lcd(0X7F)  
transfer_data_lcd(0X20) 

transfer_command_lcd(0xF0)  
transfer_data_lcd(0X10)

transfer_command_lcd(0x81)
transfer_data_lcd(0x10)
transfer_data_lcd(0x04)
transfer_command_lcd(0x20)
transfer_data_lcd(0x0B)

transfer_command_lcd(0xAF)

clear_screen()

test(2)

